//
//  HJXTopMyInfoView.m
//  Catus
//
//  Created by 晓梦影 on 16/4/18.
//  Copyright © 2016年 黄金星. All rights reserved.
//

#import "HJXTopMyInfoView.h"
#import "Masonry.h"

@interface HJXTopMyInfoView ()
/** 头像*/
//@property (nonatomic, weak) UIImageView *imageV;
@property (weak, nonatomic) IBOutlet UIImageView *imageV;

/** 昵称*/
@property (nonatomic, weak) UILabel *nameL;
/** 头衔*/
@property (nonatomic, weak) UILabel *headL;
/** 等级*/
@property (nonatomic, weak) UILabel *gradeL;
/** 签到*/
@property (nonatomic, weak) UIButton *signBtn;
/** 连续多少天*/
@property (nonatomic, weak) UILabel *textL;

@end

@implementation HJXTopMyInfoView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

+ (instancetype)topView
{
    return [[HJXTopMyInfoView alloc]init];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    // 添加子控件
    [self setUpSub];
    // 添加约束
//    [self setUpSubLayout];
  
    // 设置标题，图片
    [self setUp];
    
    return self;
}


- (void)setUpSub
{
    // 头像
    UIImageView *imageV = [[UIImageView alloc]init];
    [self addSubview:imageV];
    self.imageV = imageV;
    // 昵称
    UILabel *nameL = [[UILabel alloc]init];
    [self addSubview:nameL];
    self.nameL = nameL;
    // 头衔
    UILabel *headL = [[UILabel alloc]init];
    [self addSubview:headL];
    self.headL = headL;
    // 等级
    UILabel *gradeL = [[UILabel alloc]init];
    [self addSubview:gradeL];
    self.gradeL = gradeL;
    // 签到
    UIButton *signBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:signBtn];
    self.signBtn = signBtn;
    // 连续多少天
    UILabel *textL = [[UILabel alloc]init];
    [self addSubview:textL];
    self.textL = textL;
}


- (void)setUp
{
    self.imageV.image = [UIImage imageNamed:@"DefaultAvatar"];
    self.nameL.text = @"乌尔奇奥拉后无破面";
    self.headL.text = @"头衔:";
    self.headL.textAlignment = NSTextAlignmentRight;
    self.headL.font = [UIFont systemFontOfSize:12];
    self.gradeL.text = @"夜猫";
    self.gradeL.font = [UIFont systemFontOfSize:12];
    self.gradeL.textAlignment = NSTextAlignmentLeft;
    [self.signBtn setBackgroundImage:[UIImage imageNamed:@"daka"] forState:UIControlStateNormal];
    self.textL.text = @"(已经连续打卡0天)";
    self.textL.font = [UIFont systemFontOfSize:14];
    
    
}


- (void)layoutSubviews
{
    
   
   [super layoutSubviews];
    
    self.imageV.frame = CGRectMake(10, 10, 45, 45);
    
    /*
     [redView mas_makeConstraints:^(MASConstraintMaker *make) {
     //        make.top.equalTo(self.view.mas_top).offset(20);
     //        make.left.equalTo(self.view.mas_left).offset(20);
     //        make.right.equalTo(self.view.mas_right).offset(-20);
     //        make.bottom.equalTo(self.view.mas_bottom).offset(-20);
     //    }];
     
     
     [redView mas_makeConstraints:^(MASConstraintMaker *make) {
     //        make.top.equalTo(self.view).offset(20);
     //        make.left.equalTo(self.view).offset(20);
     //        make.right.equalTo(self.view).offset(-20);
     //        make.bottom.equalTo(self.view).offset(-20);
     //    }];
     */
    // 昵称
    [self.nameL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imageV).offset(0);
        make.left.equalTo(self.imageV.mas_right).offset(10);
        make.right.equalTo(self).offset(-10);
        make.height.mas_equalTo(20);
    }];
    // 头衔
    [self.headL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameL.mas_bottom).offset(5);
        make.left.equalTo(self.nameL).offset(0);
//        make.width.mas_equalTo();
        make.bottom.equalTo(self.imageV).offset(-5);
    }];

    // 等级
    [self.gradeL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headL).offset(0);
        make.left.equalTo(self.headL.mas_right);
        make.right.equalTo(self).offset(-10);
        make.height.mas_equalTo(self.headL);
    }];

    // 打卡
    [self.signBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imageV.mas_bottom).offset(20);
        make.left.equalTo(self.imageV);
        make.right.equalTo(self.imageV).offset(0);
        make.bottom.equalTo(self).offset(-20);
    }];

    // 连续多少天打卡
    [self.textL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.signBtn);
        make.left.equalTo(self.headL);
        make.right.equalTo(self).offset(-10);
        make.bottom.equalTo(self.signBtn);
    }];

    
}



- (void)setUpSubLayout
{
    /*
     注意:先把需要自动布局的view加入父view然后在进行自动布局
     */
//    self.nameL.sd_layout.topSpaceToView(self,30)
//    .leftSpaceToView(self,45 + 10)
//        .heightIs(44)
//        .rightSpaceToView(self,10);
    
//        self.headL.sd_layout.topSpaceToView(self.nameL,10)
//        .leftEqualToView(self.nameL)
//        .bottomSpaceToView(self.textL,20)
//        .rightSpaceToView(self.gradeL,0);
//    
//        self.gradeL.sd_layout.topEqualToView(self.headL)
//        .leftSpaceToView(self.headL,0)
//        .bottomEqualToView(self.headL)
//        .rightSpaceToView(self,10);
//    
//        self.signBtn.sd_layout.topSpaceToView(self.imageV,10)
//        .leftEqualToView(self.imageV)
//        .bottomSpaceToView(self,10)
//        .rightSpaceToView(self.textL,15);
//    
//        self.textL.sd_layout.topEqualToView(self.signBtn)
//        .leftEqualToView(self.headL)
//        .bottomEqualToView(self.signBtn)
//        .rightSpaceToView(self,10); self.nameL.sd_layout.topEqualToView(self.imageV)
//        .leftSpaceToView(self.imageV,10)
//        .bottomSpaceToView(self.headL,10)
//        .rightSpaceToView(self,10);
//    
//        self.headL.sd_layout.topSpaceToView(self.nameL,10)
//        .leftEqualToView(self.nameL)
//        .bottomSpaceToView(self.textL,20)
//        .rightSpaceToView(self.gradeL,0);
//    
//        self.gradeL.sd_layout.topEqualToView(self.headL)
//        .leftSpaceToView(self.headL,0)
//        .bottomEqualToView(self.headL)
//        .rightSpaceToView(self,10);
//    
//        self.signBtn.sd_layout.topSpaceToView(self.imageV,10)
//        .leftEqualToView(self.imageV)
//        .bottomSpaceToView(self,10)
//        .rightSpaceToView(self.textL,15);
//    
//        self.textL.sd_layout.topEqualToView(self.signBtn)
//        .leftEqualToView(self.headL)
//        .bottomEqualToView(self.signBtn)
//        .rightSpaceToView(self,10);
}



@end
